package com.atguigu.tingshu.account.receiver;


import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.model.account.UserAccount;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.atguigu.tingshu.common.rabbit.constant.MqConst.ROUTING_USER_REGISTER;

@Component
public class AccountReceiver {


    @Autowired
    private UserAccountService userAccountService;

    @RabbitListener(bindings = @QueueBinding(exchange = @Exchange(value = MqConst.EXCHANGE_USER,durable = "true"),
            value = @Queue(value = MqConst.QUEUE_USER_REGISTER,durable = "true"),
            key = MqConst.ROUTING_USER_REGISTER))
    public void userRegister(Channel channel, Message message, Long obj){
        System.out.println(obj);
        userAccountService.saveUserAccount(obj);
    }
}
